package com.atguigu.tingshu.user.api;

import com.atguigu.tingshu.common.login.MyLogin;
import com.atguigu.tingshu.common.result.Result;
import com.atguigu.tingshu.common.util.AuthContextHolder;
import com.atguigu.tingshu.user.service.UserListenProcessService;
import com.atguigu.tingshu.vo.user.UserListenProcessVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;

@Tag(name = "用户声音播放进度管理接口")
@RestController
@RequestMapping("api/user/userListenProcess")
@SuppressWarnings({"all"})
public class UserListenProcessApiController {

	@Autowired
	private UserListenProcessService userListenProcessService;

	//UserListenProcess mongoDB对应的对象
	//UserListenProcessVo 前端传进来的Vo对象
	@MyLogin
	@Operation(summary = "获取声音的上次跳出时间")
	@GetMapping("/getTrackBreakSecond/{trackId}")
	public Result<BigDecimal> getTrackBreakSecond(@PathVariable Long trackId) {
		//获取用户id
		Long userId = AuthContextHolder.getUserId();
		//调用service，根据userId + trackId
		BigDecimal breakSecond = userListenProcessService.getTrackBreakSecond(userId,trackId);
		return Result.ok(breakSecond);
	}

	@MyLogin
	@Operation(summary = "更新或更新播放进度")
	@PostMapping("/updateListenProcess")
	public Result updateListenProcess(@RequestBody UserListenProcessVo userListenProcessVo) {
		// 获取用户Id
		Long userId = AuthContextHolder.getUserId();
		// 调用服务层方法
		userListenProcessService.updateListenProcess(userId, userListenProcessVo);
		return Result.ok();
	}

}

